Post

Replies

Boosts

Views

Activity

New iOS String Initializer can't get correct localized String for specific locale
I tried to build LocalizedKeyString using String's new Initializer. String(localized: "hello",locale: locale) When I change the language setting of the device, everything works as expected. However, when I try to get the string in a specific language using the specified Locale, I can only ever get the string in .current. String(localized: "hello",locale: Locale(identifier: "zh-cn"))     func getString(locale:Locale) -> String{          String(localized: "hello",locale: locale)     } If you change the display language of the project (or the language setting of the device), the text in Text is always displayed correctly. Text(getString(locale:.current)) However, the code in onAppear print(getString(locale:Locale(identifier: "zh-cn"))) It only displays the same content as Text, but not the specified Chinese. Is it my fault that the new Initializer The understanding is not correct, or the bug of String init(localized keyAndValue: String.LocalizationValue, table: String? = nil, bundle: Bundle? = nil, locale: Locale = .current, comment: StaticString? = nil) FB number: FB9675845
7
0
5.3k
Mar ’24
Questions about CSSearchQuery and Spotlight
I have added the contents of my app to iOS Spotlight via the CSSearchableItemAttributeSet and it is very easy to find them from spotlight in use. I'd like to achieve a similar effect in the app via CSSearchQuery, but I'm currently running into a problem. In the system's spotlight, users can use fuzzy queries to find the information they want. I can't enter Chinese characters in the forum, 'hello' should be Chinese characters for example, if my content is in Chinese, 'hello', users can find the content not only by 'hello' but also by using 'nihao' to find the same content.('nihao' is the Latin pinyin equivalent of the Chinese word 'hello'). However, I am unable to achieve a similar effect in CKSearchQuery. At the moment CKSearchQuery only has [cdwt] four ways, is there any other means to achieve the above query capability. Or perhaps Apple does not have this capability open in CKSearchQuery.
2
0
1.4k
Sep ’21
Question about sharing data via Cloudkit and Core Data - Creating CKShare
I am trying to use the new API provided by WWDC21 to create Core Data databases that can be shared. When I do the sharing for an NSManageObject, I tried to experiment with 2 methods. 1: Using UICloudSharingController's UICloudSharingController(preparationHandler: (UICloudSharingController, @escaping (CKShare?, CKContainer?, Error?) -> Void) -> Void) method. Currently this method works and the participants can get all the data after accepting the invitation. 2:Use NSPersistentContainer's share(_ managedObjects: [NSManagedObject], to share: CKShare?) async throws -> (Set<NSManagedObjectID>, CKShare, CKContainer) method. First get ckshare, then call UICloudSharingController(share:, container: ) With this approach, after accepting the invitation, the participant only gets the data generated after the creation of the ckshare, and the data before the ckshare is never fetched I'm not sure if it's an error in the token generated by the share method of the NSPersistentContainer or something else. Has anyone encountered a similar situation?
1
0
1.3k
Sep ’21
A question about persistentStoreDescriptions‘s configuration
I will use persistentStoreDescriptions in many occasions to configure my Coredata. for example one description is used to synchronize cloudkit and another is set to be stored locally. For persistentStoreDescriptions I do it in the Model Editor provided by Xcode. But I always had a question. <configuration name="local" usedWithCloudKit="YES"> <memberEntity name="Student"/> </configuration> <configuration name="memory"> <memberEntity name="Teacher"/> </configuration> In the .xcdatamodeld file, in the configuration it is possible to see which Entities are included and which use use Cloudkit, but I can't see from the container, store, coordinator, persistentStoreDescriptions and NSManagedObjectModel objects to get any relationship between the configuration and the entity. I'm just curious if it's possible to see this in the code, or if it's just another piece of Apple's black magic.
0
0
774
Jul ’21
Hot to merge Predicate in SwiftData
In Core Data, I can merge two predicates (perform an OR operation) using the following code: let compound3 = NSCompoundPredicate(type: .or, subpredicates: [compound1, compound2]) How can I achieve a similar operation in SwiftData with new Predicate?
Replies
4
Boosts
3
Views
2.7k
Activity
Apr ’24
New iOS String Initializer can't get correct localized String for specific locale
I tried to build LocalizedKeyString using String's new Initializer. String(localized: "hello",locale: locale) When I change the language setting of the device, everything works as expected. However, when I try to get the string in a specific language using the specified Locale, I can only ever get the string in .current. String(localized: "hello",locale: Locale(identifier: "zh-cn"))     func getString(locale:Locale) -> String{          String(localized: "hello",locale: locale)     } If you change the display language of the project (or the language setting of the device), the text in Text is always displayed correctly. Text(getString(locale:.current)) However, the code in onAppear print(getString(locale:Locale(identifier: "zh-cn"))) It only displays the same content as Text, but not the specified Chinese. Is it my fault that the new Initializer The understanding is not correct, or the bug of String init(localized keyAndValue: String.LocalizationValue, table: String? = nil, bundle: Bundle? = nil, locale: Locale = .current, comment: StaticString? = nil) FB number: FB9675845
Replies
7
Boosts
0
Views
5.3k
Activity
Mar ’24
Questions about CSSearchQuery and Spotlight
I have added the contents of my app to iOS Spotlight via the CSSearchableItemAttributeSet and it is very easy to find them from spotlight in use. I'd like to achieve a similar effect in the app via CSSearchQuery, but I'm currently running into a problem. In the system's spotlight, users can use fuzzy queries to find the information they want. I can't enter Chinese characters in the forum, 'hello' should be Chinese characters for example, if my content is in Chinese, 'hello', users can find the content not only by 'hello' but also by using 'nihao' to find the same content.('nihao' is the Latin pinyin equivalent of the Chinese word 'hello'). However, I am unable to achieve a similar effect in CKSearchQuery. At the moment CKSearchQuery only has [cdwt] four ways, is there any other means to achieve the above query capability. Or perhaps Apple does not have this capability open in CKSearchQuery.
Replies
2
Boosts
0
Views
1.4k
Activity
Sep ’21
Question about sharing data via Cloudkit and Core Data - Creating CKShare
I am trying to use the new API provided by WWDC21 to create Core Data databases that can be shared. When I do the sharing for an NSManageObject, I tried to experiment with 2 methods. 1: Using UICloudSharingController's UICloudSharingController(preparationHandler: (UICloudSharingController, @escaping (CKShare?, CKContainer?, Error?) -> Void) -> Void) method. Currently this method works and the participants can get all the data after accepting the invitation. 2:Use NSPersistentContainer's share(_ managedObjects: [NSManagedObject], to share: CKShare?) async throws -> (Set<NSManagedObjectID>, CKShare, CKContainer) method. First get ckshare, then call UICloudSharingController(share:, container: ) With this approach, after accepting the invitation, the participant only gets the data generated after the creation of the ckshare, and the data before the ckshare is never fetched I'm not sure if it's an error in the token generated by the share method of the NSPersistentContainer or something else. Has anyone encountered a similar situation?
Replies
1
Boosts
0
Views
1.3k
Activity
Sep ’21
A question about persistentStoreDescriptions‘s configuration
I will use persistentStoreDescriptions in many occasions to configure my Coredata. for example one description is used to synchronize cloudkit and another is set to be stored locally. For persistentStoreDescriptions I do it in the Model Editor provided by Xcode. But I always had a question. <configuration name="local" usedWithCloudKit="YES"> <memberEntity name="Student"/> </configuration> <configuration name="memory"> <memberEntity name="Teacher"/> </configuration> In the .xcdatamodeld file, in the configuration it is possible to see which Entities are included and which use use Cloudkit, but I can't see from the container, store, coordinator, persistentStoreDescriptions and NSManagedObjectModel objects to get any relationship between the configuration and the entity. I'm just curious if it's possible to see this in the code, or if it's just another piece of Apple's black magic.
Replies
0
Boosts
0
Views
774
Activity
Jul ’21